<?php

namespace App\Http\Controllers;
require base_path().'/vendor/autoload.php';

use Illuminate\Http\Request;
use Qiniu\Auth;
use Qiniu\Storage\BucketManager;

class QiniuController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    public function getQiniuToken(){
        // 用于签名的公钥和私钥
        $accessKey = config('qiniu.accessKey');
        $secretKey = config('qiniu.secretKey');
        $bucket = config('qiniu.bucket');
        // 初始化签权对象
        $auth = new Auth($accessKey, $secretKey);

        $expires = 3600;
        $policy = null;
        $upToken = $auth->uploadToken($bucket, null, $expires, $policy, true);
        return json_encode(['uptoken'=>$upToken]);
    }

}
